<?php
/****
******
******商品管理:添加、修改、删除
******
****/
class GoodslabelAction extends Action
{
	public function preMethod()
	{
		R("Mayijie/check_admin");
		$perm_key = session('admin_perm');
		$perm_arr = explode(",",$perm_key);
		if(!in_array(4,$perm_arr)){
			$this->error("无权操作");
		}
	}

	public function index(){
		$Label=M('Goods_label');
		$this->goods_label=$Label->order('label_id desc')->select();
		$this->display();
	}

	public function add(){
		$Label=M('Goods_label');
	    $label_name=$this->_post('label_name');

		if(empty($label_name)) $this->error("不得为空！");
		//检查是否存在
		$map['label_name']=$label_name;
		$check=$Label->where($map)->select();
		if($check==false){
			$data['label_name']=$label_name;
			$result=$Label->add($data);
			if($result) $this->success("添加标签成功！");
		}else{
			$this->error("已经存在！");
		}
	}

	public function get_label(){
		$Label=M('Goods_label');
		return $Label->order('label_id desc')->select();
	}

}
?>